package com.halflife.framework.utils;

import com.halflife.comeElectricity.batteryCabinet.BatteryCabinet;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Rectangle;
import org.apache.commons.lang.StringUtils;

/**
 * Created by zhaoyf on 2018/3/10.
 */
public class Utils {
    public static String getUrl(BatteryCabinet c){
        String url = "http://47.105.65.229:9898";
        if (StringUtils.isNotBlank(c.getServerUrl())) {
            url = c.getServerUrl();
        }
        return url;
    }
    public static String getString(String string) {
        if (string == null) {
            return "";
        }
        return string;
    }
    public static String getString(Object string) {
        if (string == null) {
            return "";
        }
        return string.toString();
    }
    public static Rectangle disance(double longitude,double latitude,Integer radius){
        // 前端需要分析
        // 1公里之内的 所有的数据  超过60条 停止 还有
        // 不到50条 2公里之内的  1000  7 8
        // 50条来 <50条 结束  经纬度在变
        // >50条 <100条
        // 内存里面搞  id 经纬度  id 所有数据



        SpatialContext geo = SpatialContext.GEO;
        Rectangle rectangle = geo.getDistCalc().calcBoxByDistFromPt(
                geo.makePoint(longitude, latitude), radius * DistanceUtils.KM_TO_DEG, geo, null);
        System.out.println(rectangle.getMinX() + "-" + rectangle.getMaxX());// 经度范围
        System.out.println(rectangle.getMinY() + "-" + rectangle.getMaxY());// 纬度范围
        return rectangle;
    }
}
